package com.scap.dfs.service.impl;

import java.io.Serializable;
import java.util.List;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.scap.dfs.dao.DepartmentDao;
import com.scap.dfs.dao.impl.DepartmentDaoImpl;
import com.scap.dfs.model.Department;
import com.scap.dfs.model.DepartmentPK;
import com.scap.dfs.service.DepartmentService;


@Service
public class DepartmentServiceImpl implements DepartmentService {
	
	final static Logger logger = Logger.getLogger(DepartmentServiceImpl.class);
	
	@Autowired
	DepartmentDao departmentDao;
	
	@Override
	@Transactional
	public String addDepartment(Department department){		
		
		boolean result = departmentDao.insert(department);
		
		if(result){
			return "Success";
		}
		else{
			return "Fail";
		}
		
	}

	
	@Override
	@Transactional
	public String updateDepartment(Department department) {
		
		boolean result = departmentDao.update(department);
		
		if(result){
			return "Success";
		}
		else{
			return "Fail";
		}
		
	}


	@Override
	@Transactional
	public String deleteDepartment(DepartmentPK pk) {
		
		boolean result = departmentDao.delete(pk);
		
		if(result){
			return "Success";
		}
		else{
			return "Fail";
		}
		
	}


	@Override
	@Transactional
	public Department getDepartmentById(DepartmentPK pk) {
		return departmentDao.findById(pk);
	}


	@Override
	@Transactional
	public List getDepartmentList() {
		return departmentDao.getList();
	}


	@Override
	@Transactional
	public List getDepartmentListPerPage(int amount, int page,String orderByColumnName,String ascOrDesc) {
		return departmentDao.getListPerPage(amount, page, orderByColumnName, ascOrDesc);
	}


	@Override
	@Transactional
	public List getDepartmentListByAttribute(Department department) {
		return departmentDao.findByAttribute(department);
	}


	@Override
	public List getDepartmentListByAttributePerPage(Department department,
			int amount, int page,String orderByColumnName,String ascOrDesc) {
		return departmentDao.findByAttributePerPage(department,amount,page,orderByColumnName,ascOrDesc);
	}

}
